package com.sicong.admin.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sicong.admin.entity.Dict;
import com.sicong.admin.service.DictService;
import com.sicong.common.core.utils.Result;
import com.sicong.common.core.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author chenww
 * @since 2020-12-31
 */
@Api(tags = {"字典控制器"})
@RestController
@RequestMapping("/dict")
public class DictController {

    @Resource
    private DictService dictService;

    @ApiOperation("添加字典")
    @PostMapping("/save")
    public Result<Void> save(Dict dict) {
        dictService.save(dict);
        return ResultUtil.success();
    }

    @ApiOperation("删除字典")
    @DeleteMapping("/{ids}")
    public Result<Void> removeById(@ApiParam("字典id") @PathVariable String ids) {
        dictService.removeById(ids.split(","));
        return ResultUtil.success();
    }

    @ApiOperation("更新字典")
    @PutMapping("/update")
    public Result<Void> update(Dict dict) {
        dictService.updateById(dict);
        return ResultUtil.success();
    }

    @ApiOperation("分页查询字典")
    @GetMapping("/page")
    public Result<Page<Dict>> getDict(Page<Dict> page, Dict dict) {
        Page<Dict> info = dictService.page(page, Wrappers.query(dict));
        return ResultUtil.success(info);
    }

}

